package cn.kgc.dao.impl;


import cn.kgc.dao.BaseDao;
import cn.kgc.dao.UsersDao;
import cn.kgc.pojo.Users;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UsersDaoImpl extends BaseDao implements UsersDao{

    public int isUserExists(Users users) {
        int result = 0;
        String sql = "SELECT COUNT(1) FROM news_user WHERE username=? AND PASSWORD=?";
        Object[] params = {users.getUserName(),users.getPassword()};
        if (this.getConnection()){
            try {
                ResultSet rs = this.executeQuery(sql,params);
                while (rs.next()){
                    result = rs.getInt(1);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }finally {
                this.closeResource();
            }
        }
        return result;
    }
}
